/*******************************************************************
* Author	: wwyang
* Date		: 2006.3.22
* Copyright : State key CAD&CG Lab, Group of Animation 
* Head File : Manage all objects for different applications
* Version   : 1.0
*********************************************************************/

#ifndef _OBJECTMANAGE_H_
#define _OBJECTMANAGE_H_

#define MAX_OBJ_NUM	10

#include "..\Modeling\FengModeling.h"
#include "..\Modeling\VolMeshModeling.h"
#include "..\Modeling\MorfingABS.h"

//////////////////////////////////////////////////////////////////////////
// use factory to manage the objects' managers

//////////////////////////////////////////////////////////////////////////
// Base class for managing data
class CBaseObjManage{
public:
	virtual void ClearObjects()
	{
		ClearAppObjects();
		ClearDebugObjects();
	}
	virtual void ClearAppObjects() = 0;
	virtual void ClearDebugObjects() = 0; 
	// Note: the debug data is directly assigned by algorithm, but not by cmd 
};

//////////////////////////////////////////////////////////////////////////
// Class for managing the objects used for geo project
class CABSObjManage : public CBaseObjManage{
public:
	
	CABSObjManage();
	~CABSObjManage()
	{ ClearObjects(); }
	// data
private:
	MorfABSSf*		 _MorfABS[MAX_OBJ_NUM];
	VolumeModeling* _VolModeling[MAX_OBJ_NUM];
	MeshModeling* _MeshModeling[MAX_OBJ_NUM];
	FengModeling* _FengModeling[MAX_OBJ_NUM];
	ABSSf* _ABS[MAX_OBJ_NUM];
	int _modelID;

	
	// data manipulation -- get&set
public:
	int _nVol, _nMesh, _nFeng, _nABS, _nMorf;
	MorfABSSf* GetMorfABS()
	{ return _MorfABS[_nMorf-1];};
	void ResetMorfABS(){_modelID=4;}
	void SetMorfABS(MorfABSSf* morfABS)
	{if(_nMorf<MAX_OBJ_NUM){_MorfABS[_nMorf++] = morfABS; _modelID=4;}}

	VolumeModeling* GetVolumeModeling()
	{ return _VolModeling[_nVol-1];}
	void SetVolumeRendering(VolumeModeling* volModel)
	{if(_nVol<MAX_OBJ_NUM){ _VolModeling[_nVol++] = volModel; _modelID=3;}}

	MeshModeling * GetMeshModeling()
	{ return _MeshModeling[_nMesh-1]; }
	void SetMeshModeling(MeshModeling * meshMode )
	{ if(_nMesh<MAX_OBJ_NUM){_MeshModeling[_nMesh++] = meshMode; _modelID=2;}}	
	

	FengModeling * GetFengModeling()
	{ return _FengModeling[_nFeng-1]; }
	void SetFengModeling(FengModeling * fengMode )
	{ if(_nFeng<MAX_OBJ_NUM){_FengModeling[_nFeng++] = fengMode; _modelID=1;}}	
	
	ABSSf * GetABS();
	void SetABS(ABSSf * abs )
	{ if(_nABS<MAX_OBJ_NUM){_ABS[_nABS++] = abs; _modelID=0;}}

	// utility -- clear data
public:
	void ClearMorfABS();
	void ClearVolumeModeling();
	void ClearMeshModeling();
	void ClearFengModeling();
	void ClearABS();
	void ClearAppObjects();	


public:
	void ClearDebugObjects(){}
	// Clear debug data for abs project
};


//////////////////////////////////////////////////////////////////////////
// data managers' factory
class CObjManageFactory{
	// constructor & destructor
public:
	CObjManageFactory(){}
	~CObjManageFactory()
	{
		//ClearAllObject();
	}

	// get objects
public:
	static CABSObjManage& GetABSObjManage()
	{ return _absObjManage; }

	// utility functions
public:
	static void ClearAllObject();

	// IO operations
public:
	static bool LoadObject(LPCTSTR lpszPathName, bool bMorf);
	static bool WriteObject(LPCTSTR lpszPathName);
	static bool NewObject();

	static bool GenerateRandom();

	// global command objects 
private:
	static CABSObjManage _absObjManage;
};

#endif